package com.example.netty.controller;

import java.io.IOException;
import java.nio.ByteBuffer;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.netty.utils.NettyUtils;

@RestController
@CrossOrigin
@RequestMapping("/api")
public class HelloController {

    @Resource
    private NettyUtils nettyUtils;

    @RequestMapping("/hello")
    public String hello(@RequestParam("msg") String msg) throws IOException {
        nettyUtils.getSocketChannel().write(ByteBuffer.wrap(msg.getBytes()));
        return "hello";
    }
}
